<?php
/**
 * 商城每日流水
 */
namespace App\Models\MainDB\Statistics;

use Illuminate\Database\Eloquent\Model;

class MallEverydaySerial extends Model
{
    protected $table = 'ln_mall_everyday_serial';

    protected $primaryKey = 'id';

    protected $fillable = [
        'id', //主键id
        'date', //日期
        'product_cate_id', //商品分类id
        'serial', //流水
    ];

    public $timestamps = false;

    //按日期和分类进行流水统计
    public function getSum($date, $productCateId)
    {
        return $this
            ->where(function ($query) use ($date) {
                if (is_array($date)) {
                    $query->whereBetween('date', $date);
                } else {
                    $query->where('date', $date);
                }
            })
            ->where('product_cate_id', $productCateId)
            ->sum('serial');
    }
}